<style lang="scss" scoped src="./test-a.component.scss"></style>
<template>
	<div class="container-test-a">
		<div class="name-test-a">
			test-a component
		</div>
	</div>
</template>
<script lang="ts">
import { defineComponent, inject } from 'vue';
import type { InnerMqService } from '@/app/rx/service/inner-mq.service';
import type { InnerMqClient } from "@/app/rx/client/inner-mq.client";
import { Topic } from '@/app/rx/topic';

export default defineComponent({
	name: 'app-test-a',
	setup() {
		const innerMqService = inject('innerMqService') as InnerMqService;
		let client!: InnerMqClient;
		return {
			innerMqService, client,
		}
	},
	created() { // 在进入组件时，创建客户端
		this.client = this.innerMqService.createClient();
		this.client.sub(Topic.MY_TP_1, (res: string) => {
			console.log(res);
		});
	},
	beforeUnmount() { // 离开组件时，销毁客户端
		this.innerMqService.destroyClient(this.client);
		console.log('test-a销毁客户端');
	},
});
</script>
